package com.android.antelopeapp.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import com.android.antelopeapp.R;
import com.android.antelopeapp.constant.ApiConfig;
import com.android.antelopeapp.constant.MsgConfig;
import com.android.antelopeapp.network.GsonRequest;
import com.android.antelopeapp.network.NetworkManager;
import com.android.antelopeapp.view.BeautyPic.BPicListView;
import com.android.antelopeapp.view.BeautyPic.BPicView;
import com.android.antelopeapp.view.BeautyPic.RequestPicView;


/**
 * 晒装备页面
 * */
public class ShowListActivity extends BaseActivity {
    private ImageView back;
    private View actionReqPic;
    private RequestPicView mReqPic;
    private BPicListView bpicList;
    public static final String TAG = ShowListActivity.class.getName();

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        back = (ImageView) findViewById(R.id.showlist_back);
        back.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });

        /**
         * 显示获取图片的方式
         * */
        mReqPic = (RequestPicView) this.findViewById(R.id.choose_pic_requestpic);
        mReqPic.setActivity(this);

        /**获取图片按钮*/
        actionReqPic = this.findViewById(R.id.showlist_take_photo);
        actionReqPic.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mReqPic.getVisibility() == View.GONE) {
                    mReqPic.setVisibility(View.VISIBLE);
                } else {
                    mReqPic.setVisibility(View.GONE);
                }
            }
        });

        bpicList = (BPicListView) this.findViewById(R.id.card_list);
        bpicList.setHasMoreItems(true);
        bpicList.init(this);
    }

    protected int getLayoutResource() {
        return R.layout.activity_show_list;
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mReqPic.getVisibility() == View.VISIBLE) {
                mReqPic.setVisibility(View.GONE);
                return true;
            }
        }
        return super.onKeyDown(keyCode, event);
    }

    /**
     * 因为在requestpicView中，选择图片后将会进行回调，将会触发该函数
     * */
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        Log.d(this.getLocalClassName(),"onActivityResult reqcode:"+requestCode+" resCode:"+resultCode);

        if(requestCode == UploadBPicActivity.REQUEST_UPLOAD_TAGABELIMAGE){
            if(resultCode == RESULT_OK){
                toast(MsgConfig.SHARE_BPIC_OK);
            }else{
                toast(MsgConfig.SHARE_BPIC_FAILD);
            }
        }
        Log.d(this.getLocalClassName(),"is mReqPic visible :"+(mReqPic.getVisibility()==View.VISIBLE));
        if (mReqPic.getVisibility() == View.VISIBLE) {
            mReqPic.setVisibility(View.GONE);
        }
    }

}
